<template>
    <div class="remark-table">

        <div class="mb8">
            <el-button type="primary" icon="el-icon-plus" size="mini" @click="onAdd"
                       v-hasPermi="['oms:omstask:remark']">添加备注
            </el-button>
        </div>

        <el-table v-loading="loading" :data="tableList">
            <el-table-column label="备注人" prop="remarkUser"/>
            <el-table-column label="内容" prop="remarkContent"/>
            <el-table-column label="次品数" prop="remarkCps"/>
            <el-table-column label="时间" prop="remarkTime"/>
            <el-table-column label="操作">
                <el-button slot-scope="{row}" size="mini" type="text" @click="onEdit(row)"
                           v-hasPermi="['oms:omstask:remark']"
                           :disabled="$store.getters.name !== row.createBy">
                    修改
                </el-button>
            </el-table-column>
        </el-table>
        <!--分页-->
        <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
                    @pagination="getList"/>

        <!--新增弹窗-->
        <add-remark v-if="showAddEdit" :visible.sync="showAddEdit" :task-id="taskId" :data="currentItem"
                    :type="handleType" @success="resetQuery"/>

    </div>
</template>

<script>
import {handleEnum, responseEnum} from "../../../../const/const";
import {getHalfTask, getTaskDetailRemark} from "../api";
import AddRemark from "./addRemark";

export default {
    props: ['taskId'],
    components: {AddRemark},
    data() {
        return {
            loading: true,
            showAddEdit: false,
            handleType: null,
            // 查询参数
            queryParams: {
                pageNum: 1,
                pageSize: 10,
                taskId: this.taskId
            },
            // 总条数
            total: 0,
            // 表格数据
            tableList: [],

            currentItem: '',
        };
    },
    created() {
        this.getList();
    },
    methods: {

        /** 查询列表 */
        getList() {
            this.loading = true;
            getTaskDetailRemark(this.queryParams).then(res => {
                if (res.code === responseEnum.success) {
                    this.tableList = res.rows || [];
                    this.total = res.total || 0;
                }
            }).finally(() => this.loading = false);
        },

        /** 重置按钮操作 */
        resetQuery() {
            this.queryParams.pageNum = 1;
            this.getList();
        },

        /**
         * 添加备注
         */
        onAdd() {
            this.currentItem = '';
            this.handleType = handleEnum.add;
            this.showAddEdit = true;
        },
        /**
         * 修改备注
         */
        onEdit(row) {
            this.currentItem = _.cloneDeep(row);
            this.handleType = handleEnum.edit;
            this.showAddEdit = true;
        }
    }
};

</script>

<style lang="scss" scoped>

</style>
